package com.sinosoft.system.util.generate;

public class GenUtil {
	/** 
     * 功能：将输入字符串的首字母改成大写 
     * @param str 
     * @return 
     */  
    public static String initcap(String str) {  
          
        char[] ch = str.toCharArray();  
        if(ch[0] >= 'a' && ch[0] <= 'z'){  
            ch[0] = (char)(ch[0] - 32);  
        }  
          
        return new String(ch);  
    }
    /** 
     * 功能：将输入字符串的'_'去掉，并把后续的首字母改成大写 ；初始化属性名
     * @param str 
     * @return 
     */
    public static String initStr(String str){
    	str=str.toLowerCase();
    	StringBuffer sb = new StringBuffer();
    	if(str.contains("_")){
    		String[] strs = str.split("_");
    		sb.append(strs[0]);
    		for(int i=1; i<strs.length;i++){
    			sb.append(initcap(strs[i]));
    		}
    	}else{
    		sb.append(str);
    	}
    	return sb.toString();
    }
    
    /** 
     * 功能：获得列的数据类型 
     * @param sqlType  mysql
     * @return 
     */  
    public static String sqlType2JavaType(String sqlType) {  
        if(sqlType.equalsIgnoreCase("bit")){  
            return "boolean";  
        }else if(sqlType.equalsIgnoreCase("tinyint")){  
            return "byte";  
        }else if(sqlType.equalsIgnoreCase("smallint")){  
            return "short";  
//        }else if(sqlType.equalsIgnoreCase("int")){ 
        }else if(sqlType.toLowerCase().contains("int")){
            return "int";  
        }else if(sqlType.equalsIgnoreCase("bigint")){  
            return "long";  
        }else if(sqlType.equalsIgnoreCase("float")){  
            return "float";  
        }else if(sqlType.equalsIgnoreCase("decimal") || sqlType.equalsIgnoreCase("numeric")   
                || sqlType.equalsIgnoreCase("real") || sqlType.equalsIgnoreCase("money")   
                || sqlType.equalsIgnoreCase("smallmoney")){  
            return "double";  
        }else if(sqlType.equalsIgnoreCase("varchar") || sqlType.equalsIgnoreCase("char")   
                || sqlType.equalsIgnoreCase("nvarchar") || sqlType.equalsIgnoreCase("nchar")   
                || sqlType.equalsIgnoreCase("text")){  
            return "String";  
        }else if(sqlType.equalsIgnoreCase("datetime")){  
            return "Date";  
        }else if(sqlType.equalsIgnoreCase("image")){  
            return "Blod";  
        }else {
        	return "String";
        }
    }
    
    /** 
     * 功能：将输入字符串的'_'去掉，并把首字母改成大写 ,初始化类名 用于set get
     *
     * @param str 
     * @return 
     */
    public static String upcaseName(String str){
    	return initcap(initStr(str));
    }
}
